<!--Copyright (C) Kherty.  All rights reserved.-->
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    x:Class="OpenLS.Spreadsheet.UI.WorksheetResourcesHelpers"                
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ss="http://schemas.Kherty.com/office/2007/spreadsheet" 
    xmlns:ssui="clr-namespace:OpenLS.Spreadsheet.UI" 
    xmlns:Internals="clr-namespace:OpenLS.Spreadsheet.UI.Internals" 


    >
  <ResourceDictionary.MergedDictionaries>
    <ssui:WorksheetDrawingResources/>
  </ResourceDictionary.MergedDictionaries>

  <Style x:Key="cellContainerStyle">
    <Setter Property="ssui:WorksheetGrid.Row" Value="{Binding Path=Row.Index}"/>
    <Setter Property="ssui:WorksheetGrid.Column" Value="{Binding Path=Column.Index}"/>
    <Setter Property="ssui:WorksheetGrid.RowSpan" Value="{Binding Path=RowSpan}"/>
    <Setter Property="ssui:WorksheetGrid.ColumnSpan" Value="{Binding Path=ColumnSpan}"/>
  </Style>
  <Style x:Key="columnContainerStyle">
    <Setter Property="ssui:WorksheetGrid.IsFullColumn" Value="True"/>
    <Setter Property="ssui:WorksheetGrid.Column" Value="{Binding Path=Index}"/>
    <Setter Property="ssui:WorksheetGrid.ColumnSpan" Value="1"/>
  </Style>
  <Style x:Key="rowContainerStyle">
    <Setter Property="ssui:WorksheetGrid.IsFullRow" Value="True"/>
    <Setter Property="ssui:WorksheetGrid.Row" Value="{Binding Path=Index}"/>
    <Setter Property="ssui:WorksheetGrid.RowSpan" Value="1"/>
  </Style>
  <Style x:Key="drawingContainerStyle" TargetType="{x:Type FrameworkElement}" BasedOn="{StaticResource resizableControl}">
    <Setter Property="ssui:WorksheetGrid.Row" Value="{Binding Path=Cell.Row}"/>
    <Setter Property="ssui:WorksheetGrid.Column" Value="{Binding Path=Cell.Column}"/>
    <Setter Property="ssui:WorksheetGrid.ItemWidth" Value="{Binding ActualWidth}"/>
    <Setter Property="ssui:WorksheetGrid.ItemHeight" Value="{Binding ActualHeight}"/>
    <Setter Property="ssui:WorksheetGrid.RowOffset" Value="{Binding RowOffset}"/>
    <Setter Property="ssui:WorksheetGrid.ColumnOffset" Value="{Binding ColumnOffset}"/>
  </Style>
  <Style x:Key="cellTextContainerStyle" BasedOn="{StaticResource cellContainerStyle}">
    <Setter Property="ssui:WorksheetGrid.Overflow" Value="{Binding CanOverflow}"/>
  </Style>
  <DataTemplate DataType="{x:Type ss:Cell}" x:Key="cellTemplate">
    <Grid VerticalAlignment="Stretch" Background="{Binding Background}" 
                        >
      <Path Data ="M 0,0 L 6,0 L 6,6 L 0,0" Fill="Red" HorizontalAlignment="Right" VerticalAlignment="Top" 
            Visibility="{Binding Converter={x:Static ssui:BooleanToVisibilityConverter.Instance}, Path=Comment}"
            ToolTip="{Binding Path=Comment.Text}" />
      <DockPanel>
        <Rectangle Fill="Black"  Margin="-1 0 0 0" DockPanel.Dock="Left" 
                   Width="{Binding Border, Converter={x:Static Internals:SpreadsheetConverters.BorderThicknessConverter}, ConverterParameter=left}" HorizontalAlignment="Left"/>
        <Rectangle Fill="Black"  Margin="0 -1 0 0" DockPanel.Dock="Top" Height="{Binding Border, Converter={x:Static Internals:SpreadsheetConverters.BorderThicknessConverter}, ConverterParameter=top}" VerticalAlignment="Top"/>
        <Rectangle Fill="Black" DockPanel.Dock="Right" Width="{Binding Border, Converter={x:Static Internals:SpreadsheetConverters.BorderThicknessConverter}, ConverterParameter=right}" HorizontalAlignment="Right"/>
        <Rectangle Fill="Black" DockPanel.Dock="Bottom" Height="{Binding Border, Converter={x:Static Internals:SpreadsheetConverters.BorderThicknessConverter}, ConverterParameter=bottom}" VerticalAlignment="Bottom"/>
      </DockPanel>
    </Grid>
  </DataTemplate>
  <DataTemplate DataType="{x:Type ss:Column}" x:Key="columnBackgroundTemplate">
    <Rectangle VerticalAlignment="Stretch" Fill="{Binding Background}" >
    </Rectangle>
  </DataTemplate>

  <DataTemplate DataType="{x:Type ss:Row}" x:Key="rowBackgroundTemplate">
    <Rectangle HorizontalAlignment="Stretch" Fill="{Binding Background}" >
    </Rectangle>
  </DataTemplate>

  <DataTemplate DataType="{x:Type ss:Cell}" x:Key="cellTextTemplate">
    <ContentControl                
              Foreground="{Binding Foreground}" 
               FontWeight="{Binding FontWeight}" 
               FontStyle="{Binding FontStyle}" 
               FontFamily="{Binding FontFamily, Mode=OneWay}" 
               FontSize="{Binding FontSize, Converter={x:Static ss:PointsToPixelConverter.Instance}}" 
               Margin ="{Binding Indentation, Converter={x:Static Internals:SpreadsheetConverters.IndentationToThicknessConverter}}" 
            Content="{Binding FormattedValue}" ToolTip="{Binding Format}">
    </ContentControl>
    <DataTemplate.Triggers>
      <DataTrigger Binding="{Binding Value}" Value="{x:Null}">
        <Setter Property ="Visibility" Value="Collapsed"/>
      </DataTrigger>
      <DataTrigger Binding="{Binding TextWrapping}" Value="{x:Static TextWrapping.NoWrap}">
        <Setter Property ="VerticalAlignment" Value="{Binding VerticalAlignment, Mode=OneWay}"/>
        <Setter Property="HorizontalAlignment" Value="{Binding HorizontalAlignment, Mode=OneWay}"/>
      </DataTrigger>
      <DataTrigger Binding="{Binding TextWrapping}" Value="{x:Static TextWrapping.Wrap}">
        <Setter Property ="VerticalAlignment" Value="Stretch"/>
        <Setter Property ="HorizontalAlignment" Value="Stretch"/>
      </DataTrigger>
    </DataTemplate.Triggers>
  </DataTemplate> 




  <!-- <ss:AddConverter Increment="-10" x:Key="incrementer"/> -->


    <SolidColorBrush Color="Gray" x:Key="checkerBrush" Opacity="0.5"/>
  <DrawingBrush Viewport="0,0,2,2" x:Key='checkerBrushold' TileMode="Tile" ViewportUnits="Absolute" Viewbox="0,0, 2,2" ViewboxUnits="Absolute">

    <DrawingBrush.Drawing>
      <DrawingGroup>
        <DrawingGroup.Children>
          <GeometryDrawing Brush='Gray'>
            <GeometryDrawing.Geometry >
              <RectangleGeometry Rect ='0 0 1 1'/>
            </GeometryDrawing.Geometry>
          </GeometryDrawing>
          <GeometryDrawing Brush='Gray'>
            <GeometryDrawing.Geometry >
              <RectangleGeometry Rect ='1 1 2 2'/>
            </GeometryDrawing.Geometry>
          </GeometryDrawing>
        </DrawingGroup.Children>
      </DrawingGroup>
    </DrawingBrush.Drawing>
  </DrawingBrush>

  <DataTemplate DataType="{x:Type ssui:AutoFill}">
    <Grid SnapsToDevicePixels="False" ToolTipService.IsEnabled="True">
      <Rectangle Stroke="{StaticResource checkerBrush}" StrokeThickness="4" Margin="-2"/>
      <Rectangle Fill="Black" Opacity="0.3" Margin="2" Name="disabledRect" Visibility="Hidden">

      </Rectangle>
    </Grid>
    <DataTemplate.Triggers>
      <DataTrigger Binding="{Binding IsEnabled}" Value ="False">
        <Setter Property ="Visibility" Value="Visible" TargetName="disabledRect"/>
      </DataTrigger>
    </DataTemplate.Triggers>
  </DataTemplate>
  <Style x:Key="clipboardRectangle" TargetType="{x:Type Rectangle}">
    <Style.Triggers>
      <EventTrigger RoutedEvent="Rectangle.Loaded" >
        <EventTrigger.Actions>
          <BeginStoryboard Name="clipboardRect">
            <Storyboard >
              <DoubleAnimation From ="-1" To ="1" Duration="0:0:.2" RepeatBehavior="Forever"
                               Storyboard.TargetProperty="(Rectangle.Stroke).(DrawingBrush.Drawing).(DrawingGroup.Transform).(TranslateTransform.X)"/>
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger.Actions>
      </EventTrigger>
      <EventTrigger RoutedEvent="Rectangle.Unloaded" >
        <EventTrigger.Actions>
          <StopStoryboard BeginStoryboardName="clipboardRect">
          </StopStoryboard>
        </EventTrigger.Actions>
      </EventTrigger>
    </Style.Triggers>
    <Setter Property="StrokeThickness" Value="2"/>
    <Setter Property="Stroke">
      <Setter.Value>
        <DrawingBrush Viewport="0,0,10,10" x:Name='foo' TileMode="Tile" ViewportUnits="Absolute" Viewbox="0,0, 2,2" ViewboxUnits="Absolute">

          <DrawingBrush.Drawing>
            <DrawingGroup>
              <DrawingGroup.Transform>
                <TranslateTransform  x:Name='trans'/>
              </DrawingGroup.Transform>
              <DrawingGroup.Children>
                <!--                     <GeometryDrawing Geometry="M0,0.2 L0.2,0 2.2,2, 2,2.2z" Brush="Black" />
                     <GeometryDrawing Geometry="M0,1.2 L0.2,1 2.2,3, 2,3.2z" Brush="Black" /> -->
                <GeometryDrawing Geometry="M-5,-5 L10,10 L11,10 L-4,-5z" Brush="Black" />
                <GeometryDrawing Geometry="M-4,-5 L11,10 L12,10 L-3,-5z" Brush="White" />
                <GeometryDrawing Geometry="M-3,-5 L12,10 L13,10 L-2,-5z" Brush="Black" />
                <GeometryDrawing Geometry="M-2,-5 L13,10 L13,10 L-1,-5z" Brush="White" />
                <GeometryDrawing Geometry="M-1,-5 L14,10 L14.5,10 L-0.5,-5z" Brush="Black" />
                <GeometryDrawing Geometry="M-7,-5 L8,10 L8.5,10 L-6.5,-5z" Brush= "Black" />
                <GeometryDrawing Geometry="M-3,-5 L12,10 L12.5,10 L-2.5,-5z" Brush="Black" />
                <GeometryDrawing Geometry="M-3,-5 L12,10 L12.5,10 L-2.5,-5z" Brush="Black" />
              </DrawingGroup.Children>
            </DrawingGroup>
          </DrawingBrush.Drawing>
        </DrawingBrush>
      </Setter.Value>
    </Setter>

  </Style>

  <DataTemplate DataType="{x:Type ss:Range}" x:Key="realhighlight">
    <Rectangle Style="{StaticResource clipboardRectangle}"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
  </DataTemplate>

  <DataTemplate DataType="{x:Type ss:Range}" x:Key="highlight">
    <ContentPresenter ContentTemplate="{StaticResource realhighlight}" Name="cp"/>
    <DataTemplate.Triggers>
      <DataTrigger Binding="{Binding}" Value="{x:Null}">
        <Setter TargetName="cp" Property="ContentTemplate" Value="{x:Null}"/>
      </DataTrigger>
    </DataTemplate.Triggers>
  </DataTemplate>

  <VisualBrush x:Key="dragBrush" Viewport="0,0,2, 2" ViewportUnits="Absolute" TileMode="Tile">
    <VisualBrush.Visual>
      <Grid SnapsToDevicePixels="True">
        <Grid.ColumnDefinitions>
          <ColumnDefinition/>
          <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition/>
          <RowDefinition/>
        </Grid.RowDefinitions>
        <Rectangle Fill='Black' Width='1' Height='1'/>
        <Rectangle Fill='White' Width='1' Height='1' Grid.Row='1'/>
        <Rectangle Fill='White' Width='1' Height='1' Grid.Column='1'/>
        <Rectangle Fill='Black' Width='1' Height='1' Grid.Row='1' Grid.Column='1'/>
      </Grid>
    </VisualBrush.Visual>
  </VisualBrush>
  <Style TargetType ='{x:Type Rectangle}' x:Key='dragRectangle'>
    <Setter Property='Stroke' Value='{StaticResource dragBrush}'/>
    <Setter Property='StrokeThickness' Value='4'/>
    <Setter Property='Margin' Value='-1.5'/>
  </Style>



</ResourceDictionary>